package com.cysoft.lib_app_ui.ui.opensource;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.cysoft.lib_app_ui.databinding.FragmentDashboardBinding;
import com.cysoft.lib_app_ui.ui.opensource.data.DemoFuncDataAdapter;

import java.util.ArrayList;
import java.util.List;

public class DashboardFragment extends Fragment {

    private FragmentDashboardBinding binding;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        DashboardViewModel dashboardViewModel =
                new ViewModelProvider(this).get(DashboardViewModel.class);

        binding = FragmentDashboardBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        final RecyclerView demoList = binding.rvDemoList;
        initDemoFuncList(getContext(),demoList);
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    private void initDemoFuncList(Context context, RecyclerView rv) {
        rv.setLayoutManager(new LinearLayoutManager(context));
        rv.setAdapter(new DemoFuncDataAdapter(getArrayList(),getOnClickListener()));
//        rv.setItemAnimator();
        rv.addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));
    }

    private List<String> getArrayList() {
        List<String> dataList = new ArrayList<>();
        int index = 0;
        dataList.add(index++,"OKHttp Demo");
        dataList.add(index++,"Retrofit Demo");
        dataList.add(index++,"RxJava Demo");
        dataList.add(index++,"Fresco Demo");
        dataList.add(index++,"Glide Demo");
        dataList.add(index++,"Picasso Demo");
        dataList.add(index++,"Coil Demo");
        dataList.add(index++,"MultiSearchView Demo");
        dataList.add(index++,"CalendarView Demo");
        dataList.add(index++,"RubberPicker Demo");
        dataList.add(index++,"Broccoli Demo 骨架屏");

        return dataList;
    }
    private DemoFuncDataAdapter.RvItemOnClickListener getOnClickListener() {
        List<String> dataList = new ArrayList<>();
        int index = 0;
        dataList.add(index++,"/demo/okhttpdemoactivity");
        dataList.add(index++,"Retrofit Demo");
        dataList.add(index++,"RxJava Demo");
        dataList.add(index++,"Fresco Demo");
        dataList.add(index++,"Glide Demo");
        dataList.add(index++,"Picasso Demo");
        dataList.add(index++,"Coil Demo");
        dataList.add(index++,"MultiSearchView Demo");
        dataList.add(index++,"CalendarView Demo");
        dataList.add(index++,"RubberPicker Demo");
        dataList.add(index++,"Broccoli Demo 骨架屏");

        DemoFuncDataAdapter.RvItemOnClickListener onClickListener = new DemoFuncDataAdapter.RvItemOnClickListener() {
            @Override
            public void onClick(int position) {
                String path = dataList.get(position);
                ARouter.getInstance().build(path).navigation();
            }
        };

        return onClickListener;
    }
}